﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PromArrangementDB;
using WebPromenadebyenTabeller;
using PromPersonerDB;


namespace WebApptest
{
    public partial class WebFormTilmelding : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Arrangementer> listArrangementer = PromGatewayArrangementer.FindAlleArrangementer();
            foreach (Arrangementer item in listArrangementer)
            {
                var ting = "<table border=\"0\" width=\"820\" cellpadding=\"5\" cellspacing=\"10\" background=\"./images/tablebg.png\" style=\"margin-top: 30px; padding-bottom: 15px;\"><tr><td align=\"center\" width=\"200\"><h1>" + item.Overskrift + "</h1><p align=\"left\">" + item.Beskrivelse + "</p></td></tr><tr><td><a href=\"/WebFormTilmelding.aspx?id=" + item.ArrangementID + "&lid=" + Session["lejlighedsID"] + "\">Deltag i dette arrangement</a></td></td></table>";
                var arrangementerhtml = new LiteralControl(ting);
                PHArrangementer.Controls.Add(arrangementerhtml);
            }

            if (Request["lid"] != "")
            {
                tblejlighedsID.Text = Request["lid"];
            }
            if (Request["id"] != "")
            {
                tbArrangementsID.Text = Request["id"];
            }

            if (tblejlighedsID.Text != "" && tbArrangementsID.Text != "")
            {
                var show = "<div>";
                var arrangementerhtml = new LiteralControl(show);
                phShow.Controls.Add(arrangementerhtml);
            }else{
                var show2 = "<div style=\"display: none;\">";
                var arrangementerhtml2 = new LiteralControl(show2);
                phShow.Controls.Add(arrangementerhtml2);
            }

        }

        protected void btnTilmeld_Click(object sender, EventArgs e)
        {
            int lejlighedsID = int.Parse(tblejlighedsID.Text);
            int antal = int.Parse(tbAntal.Text);
            int arrangementsID = int.Parse(tbArrangementsID.Text);
            PromGatewayArrangementer.TilmeldArrangement(lejlighedsID, antal, arrangementsID);
            Label4.Text = "Du er nu tilmeldt med " + tbAntal.Text + " personer";
            tbAntal.Text = "";
        }

    }
}